package cn.tedu.ivos.dict.controller;

import cn.tedu.ivos.base.response.JsonResult;
import cn.tedu.ivos.dict.pojo.dto.DictQuery;
import cn.tedu.ivos.dict.pojo.dto.SaveDictDTO;
import cn.tedu.ivos.dict.pojo.vo.DictVO;
import cn.tedu.ivos.dict.service.DictService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author liyuehui
 * @time 2024/7/12 16:08
 */
@Slf4j
@Api(tags = "字典模块")
@RestController
@RequestMapping("/v1/dict/")
public class DictController {
    @Autowired
    private DictService dictService;

    /**
     * 查询字典列表
     * return:JsonResult
     */
    @GetMapping("select")
    @ApiOperation("查询字典列表")
    public JsonResult select(DictQuery dictQuery) {
        List<DictVO> dictList = dictService.select(dictQuery);
        log.debug("查询到" + dictList.size() + "条字典");
        return JsonResult.ok(dictList);
    }

    /**
     * 保存字典信息
     * return:JsonResult
     */
    @PostMapping("save")
    @ApiOperation("保存字典信息")
    public JsonResult save(SaveDictDTO saveDictDTO) {
        log.debug("保存字典信息:saveDictDTO={}", saveDictDTO);
        dictService.save(saveDictDTO);
        return JsonResult.ok();
    }

    /**
     * 删除字典信息
     * return:JsonResult
     */
    @PostMapping("delete/{dictId}")
    @ApiOperation("删除字典信息")
    public JsonResult delete(@PathVariable Long dictId) {
        log.debug("删除字典信息:dictId={}", dictId);
        dictService.delete(dictId);
        return JsonResult.ok();
    }
}
